package Calendar.table;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.LayoutManager;

import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import Calendar.table.day.DayPanel;
import Calendar.table.util.DayProvider;

public class DateTablePanel extends JPanel{
	
	private static final long serialVersionUID = 1L;
	
	private DateTableModel dateTableModel ;
	private JTable tableView;
	private JScrollPane scrollPane;
	
	public DateTablePanel(LayoutManager layoutManager){
		super(layoutManager);
		DayProvider dayProvider = new DayProvider();
		this.dateTableModel = new DateTableModel(dayProvider.getMonthData());
		this.tableView = new JTable(dateTableModel);
		init();
	}
	
	public void update(DateTableModel dateTableModel){
		this.tableView = new JTable(dateTableModel);
		upDateJScroll();
	}
	
	private void init(){
//		tableView.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
		tableView.setGridColor(Color.GRAY); // 星期之间的网格线是灰色的\
		tableView.setRowHeight(52);
		tableView.setColumnSelectionAllowed(true);
		tableView.setBackground(new Color(184, 207, 229));// 日期显示表格颜色浅蓝色
		tableView.getTableHeader().setReorderingAllowed(false);//表头不可移动
		tableView.getTableHeader().setResizingAllowed(false);//列大小不可改变
		//renderer
		tableView.setDefaultRenderer(DayPanel.class, new DateTableCellRenderer());
		scrollPane = new JScrollPane(tableView);
		scrollPane.setPreferredSize(new Dimension(480, 334));
		scrollPane.setBorder(BorderFactory.createEmptyBorder());
		this.add(scrollPane);
	}

	private void upDateJScroll(){
		this.remove(scrollPane);
		init();
	}
	
	public DateTableModel getDateTableModel() {
		return dateTableModel;
	}

	public void setDateTableModel(DateTableModel dateTableModel) {
		this.dateTableModel = dateTableModel;
	}
}
